/**
 * Created by WYH on 17/4/14.
 */
angular.module('leftBar', []).component(
    'leftBar',
    {
        templateUrl: 'component/base/leftBar/left_bar.template.html',
        controller: ['$rootScope' ,'$scope', 'Enum', '$state','Api', function ($rootScope, $scope, Enum, $state,Api) {

            setupLeftContent($state.current.name);
            /* 获取路由变化 */
            $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
                setupLeftContent(toState.name);
            });


            function setupLeftContent(stateName) {
                setupLeftItems(stateName);
                setupSelectedItem(stateName);
            }


            function setupLeftItems(stateName) {
                if (stateName.indexOf('company.company') != -1 || stateName == 'company') {
                    $scope.leftItems = Enum.StaffNormalLeftBarItems;
                    getCompanyDetail()
                } else if (stateName.indexOf('company.managerLock') != -1) {
                    $scope.leftItems = Enum.LocksLeftBarItems;
                } else if (stateName.indexOf('company.managerRent') != -1) {
                    $scope.leftItems = Enum.RentsLeftBarItems;
                } else if (stateName === 'account') {
                    $scope.leftItems = Enum.AccountLeftBarItems;
                }else if(stateName.indexOf('company.approve') != -1){
                    $scope.leftItems = Enum.ApproveLeftBarItems;
                }
                // console.log($scope.leftItems );
            }

            function getCompanyDetail() {
                if(!Api.getAssign()){
                    return false;
                }
                Api.getCompanyDetail(Api.getAssign(), function (result) {
                    if (!result.data.propertyNature) {
                        $scope.leftItems = Enum.StaffLeftBarItems;
                        // console.log($scope.leftItems );
                    }
                });
            }




            function setupSelectedItem(stateName) {
                if (stateName == 'company.companyStaff') {
                    $scope.selectItem = Enum.StaffLeftBarItems[1];
                } else if (stateName == 'company.companyProfile' || stateName == 'company') {
                    $scope.selectItem = Enum.StaffLeftBarItems[0];
                } else if (stateName == "company.companyLocks") {
                    $scope.selectItem = Enum.StaffLeftBarItems[2];
                } else if (stateName == "company.companyRent") {
                    $scope.selectItem = Enum.StaffLeftBarItems[3];
                } else if (stateName.indexOf('company.managerLock') != -1) {
                    $scope.selectItem = Enum.LocksLeftBarItems[0];
                } else if (stateName.indexOf('company.managerRent') != -1) {
                    $scope.selectItem = Enum.RentsLeftBarItems[0];
                } else if (stateName === 'account') {
                    $scope.selectItem = Enum.AccountLeftBarItems[0];
                } else if(stateName === 'company.approve'){
                    $scope.selectItem = Enum.ApproveLeftBarItems[0];
                }else if(stateName === 'company.companyWelfare' || stateName==='company.companyaddWelfare'){
                    $scope.selectItem = Enum.StaffLeftBarItems[4];
                }
            }


        }]
    }
);